using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;

namespace OpenWaves.ActivityFeed.Web
{
    public class HttpContextBasedUserGroupMembershipProvider : IUserGroupMembershipProvider
    {
        public IEnumerable<UserGroup> UserGroups
        {
            get
            {
                if (HttpContext.Current.User == null || !HttpContext.Current.User.Identity.IsAuthenticated || !Roles.Enabled)
                {
                    return Enumerable.Empty<UserGroup>();
                }
                return new[] { UserGroup.FromUserId(HttpContext.Current.User.Identity.Name) }.Union(Roles.GetRolesForUser(HttpContext.Current.User.Identity.Name).Select(UserGroup.FromRole));
            }
        }
    }
}